package com.example.myapplication.sound;

import android.app.Application;
import android.content.Context;
import android.media.MediaPlayer;

import com.example.myapplication.JetpackApplication;
import com.example.myapplication.R;

/**
 * Created by xiaolong on 2022/1/11 10:57 上午
 * email：xinxiaolong123@foxmail.com
 */
public class SoundPlayer {

    private static SoundPlayer player;

    private MediaPlayer mWarningPlayer;
    private MediaPlayer mCompletePlayer;

    public static SoundPlayer get() {
        if (player == null) {
            player = new SoundPlayer();
        }
        return player;
    }

    public void warning() {
        if (mWarningPlayer == null)
            mWarningPlayer = MediaPlayer.create(JetpackApplication.getInstance(), R.raw.warning);
        if (mWarningPlayer.isPlaying()) {
            mWarningPlayer.seekTo(0);
        } else {
            mWarningPlayer.start();
        }
    }

    public void complete() {
        if (mCompletePlayer == null)
            mCompletePlayer = MediaPlayer.create(JetpackApplication.getInstance(), R.raw.complete);
        if (mCompletePlayer.isPlaying()) {
            mCompletePlayer.seekTo(0);
        } else {
            mCompletePlayer.start();
        }
    }
}
